from point import Point
from cube import Cube
class Reader:
    point = None
    cubes = None
    
    
    WIDTH_OF_CUBE = 28
    HEIGHT_OF_CUBE = 19
    
    def __init__(self):
        self.cubes = []
        self.point = Point()
        
    def paint_args(self, repeat, type, magic ):
        for i in range(0,repeat):
            if type == 0:
                pass
            if type >= 1:
                p = Point()
                p.x = self.point.x
                p.y = self.point.y
                self.cubes.append(Cube(p, type, magic))
            self.point.x = self.point.x + self.WIDTH_OF_CUBE
    
    
    def handle_line(self, line):
        
        for item in line.rstrip("\n").split(","):
            if ( len(line) > 1 ):
                args = item.split(';')
                if ( len(args) == 2 ):
                    self.paint_args(int(args[0]),int(args[1]), None )
                if ( len(args) == 3 ):
                    self.paint_args(int(args[0]),int(args[1]), int(args[2]) )
                

    def read_cube_file(self, filename):
        f = open(filename, 'r')
        for line in f:
            self.handle_line(line)
            self.point.y = self.point.y + self.HEIGHT_OF_CUBE
            self.point.x = 0
        
        
if __name__ == '__main__':        
    Reader().read_cube_file('stage_1')
        